package com.nhjf.dao.postJob;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.postJob.PostJob;
import com.nhjf.pojo.qo.postJob.PostJobQo;
@Repository
public class PostJobDao extends BaseDao<PostJob, PostJobQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, PostJobQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			criteria.setFetchMode("organizationId", qo.isSeachOrganization()?FetchMode.JOIN:FetchMode.SELECT);	
			criteria.setFetchMode("typeOne", qo.isSeachTypeOne()?FetchMode.JOIN:FetchMode.SELECT);	
			criteria.setFetchMode("creatUser", qo.isSeachUser()?FetchMode.JOIN:FetchMode.SELECT);	
			if(qo.getCreatUserId()!=null) {
				 criteria.add(Restrictions.eq("creatUser.id",qo.getCreatUserId()));
			}
			if(qo.getEndTime()!=null) {
				 criteria.add(Restrictions.eq("endTime",qo.getEndTime()));
			}
			if(StringUtils.isNotBlank(qo.getName())) {
				 criteria.add(Restrictions.eq("name",qo.getName()));
			}
			if(qo.getOrganizationId()!=null) {
				criteria.add(Restrictions.eq("organizationId.id",qo.getOrganizationId()));
			}
			if(qo.getPostJobId()!=null) {
				criteria.add(Restrictions.eq("id",qo.getPostJobId()));
			}
			if(qo.getStartTime()!=null) {
				 criteria.add(Restrictions.eq("startTime",qo.getStartTime()));
			}
			if(qo.getStudentType()!=null) {
				 criteria.add(Restrictions.eq("studentType",qo.getStudentType()));
			}
			if(qo.getTypeOne()!=null) {
				criteria.add(Restrictions.eq("typeOne.id",qo.getTypeOne()));
			}
	         criteria.addOrder(Order.desc("creatTime"));
		}
		return criteria;
	}

	@Override
	protected Class<PostJob> getEntityClass() {
		// TODO Auto-generated method stub
		return PostJob.class;
	}

}
